package com.ibeetl.cms.service;

import java.util.List;

import com.ibeetl.cms.entity.IndustrialTalents;
import com.ibeetl.cms.entity.Renting;
import com.ibeetl.cms.util.ProcessConstant;
import com.ibeetl.cms.web.query.DoctoralSubsidyQuery;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ibeetl.admin.core.util.PlatformException;

import com.ibeetl.cms.dao.DoctoralSubsidyDao;
import com.ibeetl.cms.entity.DoctoralSubsidy;
import com.ibeetl.admin.core.service.BaseService;

/**
 * DoctoralSubsidy Service
 */

@Service
@Transactional
public class DoctoralSubsidyService extends BaseService<DoctoralSubsidy>{

    @Autowired
    private DoctoralSubsidyDao doctoralSubsidyDao;

    public PageQuery<DoctoralSubsidy>queryByCondition(PageQuery query){
        PageQuery ret =  doctoralSubsidyDao.queryByCondition(query);
        queryListAfter(ret.getList());
        return ret;
    }

    public void batchDelDoctoralSubsidy(List<Long> ids){
        try {
            doctoralSubsidyDao.batchDelDoctoralSubsidyByIds(ids);
        } catch (Exception e) {
            throw new PlatformException("批量删除DoctoralSubsidy失败", e);
        }
    }

    public PageQuery<DoctoralSubsidy> queryEmployees(PageQuery page) {
        page.setPageSize(Integer.MAX_VALUE);

        PageQuery ret =  doctoralSubsidyDao.queryEmployees(page);
        queryListAfter(ret.getList());
        return ret;
    }

    //查企业
    public PageQuery<DoctoralSubsidy>findenterprise(PageQuery query){
        PageQuery ret =  doctoralSubsidyDao.findenterprise(query);
        queryListAfter(ret.getList());
        return ret;
    }

    public List<DoctoralSubsidy>queryCompany(DoctoralSubsidyQuery condtion){
        List<DoctoralSubsidy> ret =  doctoralSubsidyDao.queryCompany(condtion);
        queryListAfter(ret);
        return ret;
    }

    public PageQuery<DoctoralSubsidy> queryDoneTask(PageQuery page) {
        PageQuery ret =  doctoralSubsidyDao.queryDoneTask(page);
        queryListAfter(ret.getList());
        return ret;

    }

    /**
     *根据用户id查询本年度是否已申请博士在站申报（用于医疗保障判断）
     */
    public Boolean findYear(Long userId,String year){
        return  doctoralSubsidyDao.findYear(userId,year)>0;
    }

    public int queryEmployeesCount(DoctoralSubsidyQuery condition) {
        return doctoralSubsidyDao.queryEmployeesCount(condition);
    }

    /**
     * 根据user_id查询已生效的在站人才业务数目
     * @param userId
     * @return
     */
    public  int finddoneStr(Long userId){
        return doctoralSubsidyDao.finddoneStr(userId, ProcessConstant.DONE);
    }
}